/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package opennlp.wrappers;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Luis A Riveros
 */
public class OpenNLPModelsManager {

    private static OpenNLPModelsManager instance;

    /**
     * 
     * @return
     */
    public static OpenNLPModelsManager getInstance() {
        if (instance == null) {
            instance = new OpenNLPModelsManager();
        }
        return instance;
    }

    /**
     * 
     */
    public enum LANGUAGE {

        /**
         * 
         */
        EN("en"),
        /**
         * 
         */
        ES("es");
        private String name;

        private LANGUAGE(String semanticSimilarityName) {
            this.name = semanticSimilarityName;
        }

        /**
         * 
         * @return
         */
        public String getName() {
            return name;
        }
    }

    /**
     * 
     */
    public enum MODEL_TYPE {

        /**
         * 
         */
        TOKENIZER("token"),
        /**
         * 
         */
        SENTENCE_DETECTOR("sent"),
        /**
         * 
         */
        POS_TAGGER_MAXENT("pos-maxent"),
        /**
         * 
         */
        POS_TAGGER_PERCEPTRON("pos-perceptron"),
        /**
         * 
         */
        NAME_FINDER_DATE("ner-date"),
        /**
         * 
         */
        NAME_FINDER_LOCATION("ner-location"),
        /**
         * 
         */
        NAME_FINDER_MONEY("ner-money"),
        /**
         * 
         */
        NAME_FINDER_ORGANIZATION("ner-organization"),
        /**
         * 
         */
        NAME_FINDER_PERCENTAGE("ner-percentage"),
        /**
         * 
         */
        NAME_FINDER_PERSON("ner-person"),
        /**
         * 
         */
        NAME_FINDER_TIME("ner-time"),
        /**
         * 
         */
        NAME_FINDER_MISC("ner-misc"),
        /**
         * 
         */
        CHUNKER("chunker"),
        //Only for english
        /**
         * 
         */
        PARSER("parser-chunking"),
        /**
         * 
         */
        COREFERENCE("coref");
        private String name;

        private MODEL_TYPE(String semanticSimilarityName) {
            this.name = semanticSimilarityName;
        }

        /**
         * 
         * @return
         */
        public String getName() {
            return name;
        }
    }
    private String MODELS_DIRECTORY;
    private ResourceBundle resourceBundle;

    private OpenNLPModelsManager() {
        resourceBundle = ResourceBundle.getBundle("OpenNLPData");
        MODELS_DIRECTORY = resourceBundle.getString("models_directory");
        if (!MODELS_DIRECTORY.endsWith(File.separator)) {
            MODELS_DIRECTORY += File.separator;
        }
    }

    /**
     * 
     * @param model_type
     * @param language
     * @return
     */
    public InputStream loadModel(MODEL_TYPE model_type, LANGUAGE language) throws FileNotFoundException {
        InputStream modelIn = null;
        modelIn = new FileInputStream(MODELS_DIRECTORY + language.getName() + "-" + model_type.getName() + ".bin");
        return modelIn;
    }
}
